package com.eboss2.sbs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.enums.EnumConsts;
import com.eboss2.sbs.model.WalletDrawLogEntity;
import com.mytools.tool.utils.StringUtil;
import com.mytools.tool.utils.TimeUtil;

import java.util.Date;
import java.util.List;

public class MyWalletDrawLogsAdapter extends BaseAdapter {
	
	private Context context;
	private List<WalletDrawLogEntity> datas;
	private LayoutInflater inflater;
	private ViewHolder holder = null;

	public MyWalletDrawLogsAdapter(Context context, List<WalletDrawLogEntity> datas) {
		this.context = context;
		this.datas = datas;
	}

	@Override
	public int getCount() {
		if(datas!=null&&datas.size()>0)return datas.size();
		else return 0;
	}

	@Override
	public WalletDrawLogEntity getItem(int position) {
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		WalletDrawLogEntity data = datas.get(position);
		
		inflater = LayoutInflater.from(context);

		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.listitem_wallet_log, null);
			
			holder.tv_requestTime = (TextView) convertView.findViewById(R.id.tv_requestTime);
			holder.tv_balance = (TextView) convertView.findViewById(R.id.tv_balance);
			holder.tv_status = (TextView) convertView.findViewById(R.id.tv_status);
			holder.tv_drawMoney = (TextView) convertView.findViewById(R.id.tv_drawMoney);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.tv_requestTime.setText(TimeUtil.getStringFromDate(new Date(data.getRequestTime()), "yyyy-MM-dd"));
		holder.tv_balance.setText(StringUtil.getMoneyString(data.getBalance())+" 元");
		holder.tv_status.setText(EnumConsts.WalletDrawStatus.getNameByStatus(data.getStatus()));
		holder.tv_drawMoney.setText(StringUtil.getMoneyString(data.getDrawMoney())+" 元");

		return convertView;
	}

	public final class ViewHolder {
		private TextView tv_requestTime;
		private TextView tv_balance;
		private TextView tv_status;
		private TextView tv_drawMoney;
	}

}
